package com.lh.music.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lh.music.R;
import com.lh.music.entity.NetSong;

import java.util.List;

/**
 * Created by a on 2016/12/14.
 */

public class NetSongAdapter extends BaseAdapter {
    private Context context;
    private List<NetSong> mData;

    public NetSongAdapter(Context context, List<NetSong> mData) {
        this.context = context;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView= LayoutInflater.from(context)
                    .inflate(R.layout.adapter_paihang_detail,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.name.setText(mData.get(position).getTitle());
        //加载排行歌手
        if (TextUtils.isEmpty(mData.get(position).getArtist())){
            holder.artist.setText(mData.get(position).getArtist_name());
        }//加载电台歌手
        else{
            holder.artist.setText(mData.get(position).getArtist());
        }
        //加载排行图片
        if (TextUtils.isEmpty(mData.get(position).getThumb())){
            Glide.with(context)
                    .load(mData.get(position).getPic_big())
                    .placeholder(R.mipmap.a9d)
                    .crossFade()
                    .centerCrop()
                    .into(holder.icon);
        }//加载电台图片
        else{
            Glide.with(context)
                    .load(mData.get(position).getThumb())
                    .placeholder(R.mipmap.a9d)
                    .crossFade()
                    .centerCrop()
                    .into(holder.icon);
        }

        return convertView;
    }
    static class ViewHolder{
        ImageView icon;
        TextView name;
        TextView artist;
        public ViewHolder(View view){
            icon= (ImageView) view.findViewById(R.id.icon);
            name= (TextView) view.findViewById(R.id.name);
            artist= (TextView) view.findViewById(R.id.artist);
        }
    }
}
